package cn.newstrength.shihaipeng.step;

import cn.newstrength.wtdf.plugin.param.TranParams;
import cn.newstrength.wtdf.plugin.result.PageableResult;
import cn.newstrength.wtdf.plugin.result.TranResult;
import cn.newstrength.wtdf.web.databus.DataContext;
import cn.newstrength.wtdf.web.exception.PAIException;
import cn.newstrength.wtdf.web.mybatis.service.MapperService;
import cn.newstrength.wtdf.web.mybatis.service.impl.MapperServiceImpl;
import cn.newstrength.wtdf.web.processor.Operation;
import cn.newstrength.wtdf.web.processor.OperationStep;
import cn.newstrength.wtdf.web.util.StepUtils;
import java.util.List;
import java.util.Map;

public class QueryForListPageStep implements OperationStep {
    public QueryForListPageStep() {
    }

    public int excute(Operation oper) throws PAIException {
        DataContext dc = oper.getContext();
        String mapSet = dc.getElementValue("mapSet");
        Map<String, Object> input = StepUtils.getInputValue(oper, mapSet);
        String resource = dc.getElementValue("resource");
        if (resource != null && !"".equals(resource)) {
            Integer currentPage = StepUtils.toInteger(input.get("currentPage"), 1);
            Integer pageSize = StepUtils.toInteger(input.get("pageSize"), 15);
            MapperService service = (MapperService)oper.getBean("mapperService", MapperServiceImpl.class);
            TranParams<Map<String, Object>> params = new TranParams(input);
            params.setCurrentPage(currentPage);
            params.setPageSize(pageSize);
            params.setResource(resource);
            params.setSummary("分页数据查询");
            params.setTranType("QueryForListPageStep");
            TranResult<PageableResult<List<Map<String, Object>>>> tranResult = service.listPage(params);
            oper.setTranResult(tranResult);
            return 0;
        } else {
            dc.setTranStepResult(-1, "请设置查询 Resource", (Object)null);
            return -1;
        }
    }

    public int init(Map<String, String> param) {
        return 0;
    }
}

